﻿namespace DesktopRibbon.Helper
{
    using System.Windows;
    using Microsoft.Windows.Controls.Ribbon;

    /// <summary>
    /// Helps navigating in and adding to ribbon control elements.
    /// </summary>
    class RibbonControlHelper
    {
        /// <summary>
        /// Adds element to ribbonElement's parent container (e.g. a RibbonGroup or a RibbonTab). corner specifies where ribbonElement will 
        /// be positioned relative to element.
        /// </summary>
        /// <param name="element">The element that the ribbonElement will be added next to.</param>
        /// <param name="ribbonElement">The ribbon element that will be added to element's parent.</param>
        /// <param name="corner">The position relative to element where ribbonElement will be added.</param>
        public static void AddAsSibling(UIElement element, FrameworkElement ribbonElement, Corner corner)
        {
            if (element is RibbonButton)
            {
                var btn = (RibbonButton) element;
                var parent = btn.Parent;

                if (parent is RibbonGroup)
                {
                    var group = (RibbonGroup) parent;
                    group.Items.Add(ribbonElement);
                }
            }
        }
    }
}
